package ais.dcproject.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import ais.dcproject.dao.ApplyDao;
import ais.dcproject.model.ApplyInfo;

public class ApplyDaoImpl implements ApplyDao{
	
	private SessionFactory sessionFactory;
	
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	public void delete(Integer id) {
		Session session = sessionFactory.getCurrentSession();
		session.delete("delete from ApplyInfo where id = ?", id);
	}

	public ApplyInfo get(Integer id) {
		Session session = sessionFactory.getCurrentSession();
		Query query = session.createQuery("from ApplyInfo where id = ?");
		query.setInteger(0, id);
		return (ApplyInfo) query.uniqueResult();
	}

	public ApplyInfo get(String stuNum, String idCard) {
		Session session = sessionFactory.getCurrentSession();
		Query query = session.createQuery("from ApplyInfo where stuNum = ? and idCard = ?");
		query.setString(0, stuNum);
		query.setString(1, idCard);
		return (ApplyInfo) query.uniqueResult();
	}

	public List getApplyInfosByCondition(String[] conditionClauses,
			Object[] conditionValues) {
		return null;
	}

	public void save(ApplyInfo applyInfo) {
		Session session = sessionFactory.getCurrentSession();
		session.save(applyInfo);
	}

	public void update(ApplyInfo applyInfo) {
		Session session = sessionFactory.getCurrentSession();
		session.update(applyInfo);
	}
	
}
